package com.ncs.page;

import com.ncs.pojo.Product;

import java.util.List;

/**
 * @author yinyin
 * @create 2021/07/19 下午 8:05
 */
public class PageResult<T> {
    private Integer totalCount;
    private List<T> data;
    private Integer currentPage;
    private Integer pageSize;

    //计算
    private Integer totalPage;
    private Integer prevPage;
    private Integer nextPage;

    public PageResult(Integer totalCount,Integer currentPage,  Integer pageSize,List<T> data) {
        this.totalCount = totalCount;
        this.data = data;
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        //计算
        this.totalPage = totalCount % pageSize == 0 ? totalCount / pageSize : totalCount / pageSize + 1;
        this.prevPage = currentPage - 1 > 0 ? currentPage - 1 : 1;
        this.nextPage = currentPage + 1 > this.totalPage ? this.totalPage : currentPage + 1;
    }

    @Override
    public String toString() {
        return "PageResult{" +
                "totalCount=" + totalCount +
                ", currentPage=" + currentPage +
                ", pageSize=" + pageSize +
                ", data=" + data +
                ", totalPage=" + totalPage +
                ", prevPage=" + prevPage +
                ", nextPage=" + nextPage +
                '}';
    }
}
